<?php
/**
 * @file tags.php
 * @author CaoQiCheng
 * @date 2017年2月8日 下午17:05:11
 * @brief 
 */
namespace haibao\jiepai\business;

use haibao\jiepai\data\AppVersions as AppVersionsData;
use haibao\jiepai\model\data\app\CmsAppVersions as CmsAppVersionsModel;

class AppVersions extends \haibao\jiepai\business\Base{	
	
	/**
	 * 状态码
	 */
	public static $phoneOS = array(
			CmsAppVersionsModel::PHONEOS_APPLE => '苹果',
			CmsAppVersionsModel::PHONEOS_ANDROID => '安卓',
			CmsAppVersionsModel::PHONEOS_DOUBLE => '苹果/安卓'
	);

	/**
	 * 状态码
	 */
	public static $updateVersion = array(
			CmsAppVersionsModel::STATUS_ADVICE => '建议升级',
			CmsAppVersionsModel::STATUS_FORCE => '强制升级',
	);
	
	/**
	 * 添加数据
	 */
	public static function saveAppVersion($appVersionModel,$imageIdArr){
		if(!$appVersionModel->AppVersion){
			throw new BusinessException('版本信息不能为空!');
		}
		if(!$appVersionModel->PhoneOS){
			throw new BusinessException('平台不可为空!');
		}
		if(!$appVersionModel->UpdateTime){
			throw new BusinessException('更新时间不可为空!');
		}
		if(!$appVersionModel->Id){
			if(in_array(\haibao\cms\business\base::getCurrentUser()->Id,array_keys(\haibao\jiepai\business\Base::$userMap))){
				$appVersionModel->UserID = \haibao\jiepai\business\Base::$userMap[\haibao\cms\business\base::getCurrentUser()->Id]['id'];
			}else {
				$appVersionModel->UserID = 5;
			}
			$appVersionModel->Flag = CmsAppVersionsModel::FLAG_IS;
			$appVersionModel->CreateTime = new \DateTime();
		}
		$imageIdArr = explode(',', $imageIdArr);
		$data = new AppVersionsData();
		return $data->saveAppVersion($appVersionModel,$imageIdArr);
	}
	
	/**
	 * 
	 */
	public static function getOneById($id){
		$data = new AppVersionsData();
		return $data->getOneById($id);
	}
	
	/**
	 * 查询数据
	 */
	public static function getAppVersionByFilter($query){
		$data = new AppVersionsData();
		return $data->getAll($query);
	}
	
}